<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Name:  Students_listing Model
*
* Author:  Ervin R. Musngi
*
*/

class Subject_listing_m extends DataMapperExt
{
	var $table = 'subject_listings';
    
    var $has_many = array(
                    
            );
	
	var $has_one = array(
        
            'school_level_listings'	=> array(
				'class'				=> 'school_level_m',
				'other_field'		=> 'subject_listings',
				'join_other_as'		=> 'school_level',
				'join_table'		=> 'subject_listings'
			),
            'teacher'               => array(
                   'class'          => 'users_m',
                   'other_field'    => 'subjects',
                   'join_self_as'   => 'subject_listing',
                   'join_other_as'  => 'teacher',
                   'join_table'     => 'teacher_subjects'
            )      
    );
    
    
    public function get_all( $section_id , $school_level_id ,$school_year_id)
    {
        
        $subject_list = new Subject_listing_m();

        $subject_list->where('school_level_id',$school_level_id)->where('school_year_id',$school_year_id)->get();
        
        $data = array();
        foreach ($subject_list as $s)
        {
            $data[] = (object)array(
                'subject'   => $s,
                'teacher'   => $s->teacher->where('section_listing_id',$section_id)->get()
            );
        }
        
        return $data;                       
    }
    
}